package com._21cn._front.utils;

import com._21cn.framework.utils.StringUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PageUtil {
    //黄页
    private static Pattern PC_YELLOW_PAGE_LIST = Pattern.compile("(/yellow/pc/list.shtml$)");
    private static Pattern PC_YELLOW_PAGE_CONTENT = Pattern.compile("(/yellow/pc/(\\d+).shtml$)");
    private static Pattern WAP_YELLOW_PAGE_LIST = Pattern.compile("(/yellow/wap/list.shtml$)");
    private static Pattern WAP_YELLOW_PAGE_CONTENT = Pattern.compile("(/yellow/wap/(\\d+).shtml$)");

    //抵押车
    private static Pattern PC_PLEDGE_PAGE_LIST = Pattern.compile("(/pledge/pc/list.shtml$)");
    private static Pattern PC_PLEDGE_PAGE_CONTENT = Pattern.compile("(/pledge/pc/(\\d+).shtml$)");
    private static Pattern WAP_PLEDGE_PAGE_LIST = Pattern.compile("(/pledge/wap/list.shtml$)");
    private static Pattern WAP_PLEDGE_PAGE_CONTENT = Pattern.compile("(/pledge/wap/(\\d+).shtml$)");

    //二手车
    private static Pattern PC_SECOND_PAGE_LIST = Pattern.compile("(/second/pc/list.shtml$)");
    private static Pattern PC_SECOND_PAGE_CONTENT = Pattern.compile("(/second/pc/(\\d+).shtml$)");
    private static Pattern WAP_SECOND_PAGE_LIST = Pattern.compile("(/second/wap/list.shtml$)");
    private static Pattern WAP_SECOND_PAGE_CONTENT = Pattern.compile("(/second/wap/(\\d+).shtml$)");

    //手表
    private static Pattern PC_WATCH_PAGE_LIST = Pattern.compile("(/watch/pc/list.shtml$)");
    private static Pattern PC_WATCH_PAGE_CONTENT = Pattern.compile("(/watch/pc/(\\d+).shtml$)");
    private static Pattern WAP_WATCH_PAGE_LIST = Pattern.compile("(/watch/wap/list.shtml$)");
    private static Pattern WAP_WATCH_PAGE_CONTENT = Pattern.compile("(/watch/wap/(\\d+).shtml$)");

    public static String getPageBean(String url) {
        //黄页
        Matcher regexpMatcher = PC_YELLOW_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "pcYellowPageList";
        }
        regexpMatcher = PC_YELLOW_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "pcYellowPageContent";
        }
        regexpMatcher = WAP_YELLOW_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "wapYellowPageList";
        }
        regexpMatcher = WAP_YELLOW_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "wapYellowPageContent";
        }

        //抵押车
        regexpMatcher = PC_PLEDGE_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "pcPledgeCarPageList";
        }
        regexpMatcher = PC_PLEDGE_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "pcPledgeCarPageContent";
        }
        regexpMatcher = WAP_PLEDGE_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "wapPledgeCarPageList";
        }
        regexpMatcher = WAP_PLEDGE_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "wapPledgeCarPageContent";
        }

        //二手车
        regexpMatcher = PC_SECOND_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "pcSecondCarPageList";
        }
        regexpMatcher = PC_SECOND_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "pcSecondCarPageContent";
        }
        regexpMatcher = WAP_SECOND_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "wapSecondCarPageList";
        }
        regexpMatcher = WAP_SECOND_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "wapSecondCarPageContent";
        }

        //手表
        regexpMatcher = PC_WATCH_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "pcWatchPageList";
        }
        regexpMatcher = PC_WATCH_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "pcWatchPageContent";
        }
        regexpMatcher = WAP_WATCH_PAGE_LIST.matcher(url);
        if (regexpMatcher.find()) {
            return "wapWatchPageList";
        }
        regexpMatcher = WAP_WATCH_PAGE_CONTENT.matcher(url);
        if (regexpMatcher.find()) {
            return "wapWatchPageContent";
        }
        return "";
    }

    public static void main(String[] args) {
        String labels = "{\n" +
                "    \"actLabels\": [\n" +
                "        12987,\n" +
                "        12943\n" +
                "    ],\n" +
                "    \"appLabels\": [\n" +
                "        13139,\n" +
                "        13138,\n" +
                "        13136\n" +
                "    ],\n" +
                "    \"newActLabels\": [\n" +
                "        \"爆屏\",\n" +
                "        \"花屏\"\n" +
                "    ],\n" +
                "    \"newAppLabels\": [\n" +
                "        \"赔钱\",\n" +
                "        \"道歉\"\n" +
                "    ]\n" +
                "}";

        List<String> list = new ArrayList<String>();
        try {
            if( !StringUtil.isEmpty(labels) ){
                JSONObject jsonObject = JSONObject.parseObject(labels);
                if(jsonObject!=null){
                    JSONArray jsonArray =jsonObject.getJSONArray("newAppLabels");
                    for(Object obj : jsonArray){
                        list.add(obj.toString());
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            System.out.println(list);
        }
    }
}